package memberdemo;

/**
 * 演示类的成员变量和成员方法的示例类
 */
public class DemoClass {
    // 实例成员变量
    private String name;
    private int age;
    private boolean active;
    
    // 静态成员变量
    private static int instanceCount = 0;
    
    // 常量成员变量
    public static final String DEFAULT_NAME = "Unknown";
    public static final int DEFAULT_AGE = 0;
    
    /**
     * 默认构造方法
     */
    public DemoClass() {
        this.name = DEFAULT_NAME;
        this.age = DEFAULT_AGE;
        this.active = false;
        instanceCount++;
    }
    
    /**
     * 带参数的构造方法
     * @param name 姓名
     * @param age 年龄
     */
    public DemoClass(String name, int age) {
        this.name = name;
        this.age = age;
        this.active = true;
        instanceCount++;
    }
    
    /**
     * 完整参数的构造方法
     * @param name 姓名
     * @param age 年龄
     * @param active 是否激活
     */
    public DemoClass(String name, int age, boolean active) {
        this.name = name;
        this.age = age;
        this.active = active;
        instanceCount++;
    }
    
    // Getter方法 - 实例成员方法
    public String getName() {
        return name;
    }
    
    public int getAge() {
        return age;
    }
    
    public boolean isActive() {
        return active;
    }
    
    // Setter方法 - 实例成员方法
    public void setName(String name) {
        this.name = name;
    }
    
    public void setAge(int age) {
        if (age >= 0) {
            this.age = age;
        }
    }
    
    public void setActive(boolean active) {
        this.active = active;
    }
    
    // 业务逻辑方法 - 实例成员方法
    public void birthday() {
        this.age++;
        System.out.println(name + "现在" + age + "岁了！");
    }
    
    public void activate() {
        this.active = true;
        System.out.println(name + "已激活");
    }
    
    public void deactivate() {
        this.active = false;
        System.out.println(name + "已停用");
    }
    
    public String getProfile() {
        return "姓名: " + name + ", 年龄: " + age + ", 状态: " + (active ? "激活" : "未激活");
    }
    
    // 静态方法 - 类成员方法
    public static int getInstanceCount() {
        return instanceCount;
    }
    
    public static void printClassInfo() {
        System.out.println("这是DemoClass类，用于演示成员变量和成员方法");
        System.out.println("实例计数: " + getInstanceCount());
    }
    
    // 重写toString方法
    @Override
    public String toString() {
        return "DemoClass{name='" + name + "', age=" + age + ", active=" + active + "}";
    }
}